<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../../css/style.css" />
<script type="text/javascript" src="../js/httpRequest.js"></script>
<script type="text/javascript">

var checking_num = 0;


function getTitle(cate_no){
	//alert(cate_no);
	sendRequest("../ajax/get_title.jsp", "cate_no="+cate_no, resultTitle, "POST");
}



function menuChange(val){
	var sel = document.getElementById("menu_change");
	var state="";
	var menu_no=${menu_no};
	var cate_no=${cate_no};
	var title_no=${title_no};
	//alert(sel.options[1].text);
	if(val==menu_no){
		state="category_list";		
	}else if(val==cate_no){
		state="title_list";
	}else if(val==title_no){
		state="subject_list";
	}
	alert(state);
	var param = "value="+val+"&state="+state;
	sendRequest("../ajax/get_list.jsp", param, resultList, "POST");
}
function resultList(){
	if(xhr.readyState==4 && xhr.status==200){
		var res=eval(xhr.responseText);
		var tb_list=document.getElementById("tb_list").childNodes[1];
		del(tb_list);
		for(var i=0; i<res.length; i++){
			var tr_1 = document.createElement("tr");
			var td_1 = document.createElement("td");
			var td_2 = document.createElement("td");
			var radio = document.createElement("input");
				radio.setAttribute("type","radio");
				radio.setAttribute("id","choice_"+i);
			if(res[i].cate_name!=null){
				radio.setAttribute("value",res[i].cate_no);
				td_1.innerHTML=res[i].cate_name;
				
			}else if(res[i].title_name!=null){
				radio.setAttribute("value",res[i].title_no);
				td_1.innerHTML=res[i].title_name;
				
			}else if(res[i].subject!=null){
				radio.setAttribute("value",res[i].subject);
				td_1.innerHTML=res[i].subject;
				
			}
			td_2.appendChild(radio);
			tr_1.appendChild(td_1);
			tr_1.appendChild(td_2);
			tb_list.appendChild(tr_1);
		}
	}
}

function del(ob){
	var t_v = ob;
	var cnt = t_v.childNodes.length;
	//alert(cnt);
	for(var i=0; i<cnt; i++){
		t_v.removeChild(t_v.childNodes[0]);
	}
}

</script>
</head>
<body>
	<div class="box">
			<h3>
				<p>Welcome to</p>
			 <p>Java Programing!</p>
			</h3>
	</div>
		
		
		
	<div class="box"  >
		<select id="menu_change" onchange="menuChange(this.value)">
			<option value="">::수정할 메뉴선택::</option>
			<option value="${menu_no }">카테고리</option>
			<option value="${cate_no }">타이틀</option>
			<option value="${title_no }">제목</option>
		</select>
		<form name="f1">
			<div id="dv_cate">
				<div style="border:1px solid yellow; width:30%; position: relative; float:left;">
				<table id="tb_list">
					<thead></thead>
					<tbody>
					</tbody>	
				</table>
				</div>
				<div id="btn" style="border:1px solid yellow; width:30%; float:left;">
				
				</div>	
			</div>
		</form>
	</div>
			
</body>
</html>